package ipaintplugin.actions;

import java.awt.Container;
import java.io.File;
import java.io.IOException;
import java.util.Random;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.ide.IDE;

/**
 * Our sample action implements workbench action delegate. The action proxy will
 * be created by the workbench and shown in the UI. When the user tries to use
 * the action, this delegate will be created and execution will be delegated to
 * it.
 * 
 * @see IWorkbenchWindowActionDelegate
 */
public class NewDocumentAction extends Action implements IWorkbenchAction {

	private static final String PML_EDITOR_ID = "ipaintplugin.editors.MultiPaintEditor";

	private static final String ID = "ipaintplugin.actions.newdocument";

	public NewDocumentAction() {
		setId(ID);
		setText("New Document");
	}

	public void run() {
		Random random = new Random();

		try {

			IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow()
					.getActivePage(), File.createTempFile("tmp",
					random.nextInt() + "").toURI(), PML_EDITOR_ID, true);
		} catch (PartInitException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void dispose() {
	}

}